// 应用层 游戏业务开发

module.exports=function (playerAction){
    const ALLACTION=['rock','scissor','paper']
    if (ALLACTION.indexOf(playerAction)==-1){
        throw new Error('invalid playerAction')
    }
    let computerAction;
    let random=Math.floor(Math.random()*3)
    // console.log(playerAction)
    computerAction=ALLACTION[random]
    if(computerAction==playerAction){
        console.log('平局')
        return 0;
    }else if(
        (computerAction=='rock' && playerAction=='scissor') ||
        (computerAction=='scissor' && playerAction=='paper') ||
        (computerAction=='paper' && playerAction=='rock') 
    ){
        console.log('电脑赢了')
        return -1;
    }else{
        console.log('你赢了')
        return 1;
    }
}